package org.example.ag_notes.dto.response;

import java.util.function.Supplier;

/**
 * 通用响应基类
 * @param <T> 数据类型
 */
public class Response<T> {
    private final int status;
    private final String message;
    private final T data;
    private final long timestamp;

    private Response(int status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
        this.timestamp = System.currentTimeMillis();
    }

    // 添加protected无参构造
    private Response() {
        this.status = 0;
        this.message = null;
        this.data = null;
        this.timestamp = 0L;
    }

    // Getter方法
    public int getStatus() {
        return status;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }

    public long getTimestamp() {
        return timestamp;
    }

    // 成功响应快捷方法
    public static <T> Response<T> success(T data) {
        return new Response<>(200, "Success", data);
    }
    public static <T> Response<T> success(String message, T data) {
        return new Response<>(200, message, data);
    }

    // 错误响应快捷方法
    public static <T> Response<T> error(int status, String message) {
        return new Response<>(status, message, null);
    }

    // 无数据的成功响应
    public static Response<Void> success() {
        return success("Success", null);
    }

}